// Synthetic.hpp
#ifndef SYNTHETIC_HPP
#define SYNTHETIC_HPP

#include <QObject>
#include <QList>
#include <QDateTime>
#include <QUuid>
#include <QJsonObject>
#include <QJsonArray>
#include <QJsonValue>
#include "DurationCarrier.hpp"
#include "LadderLineCarrier.hpp"

struct Synthetic {
    QString id;
    QDateTime startTime;
    QDateTime endTime;
    QList<DurationCarrier> durations; // 使用 QList
    QList<LadderLineCarrier> ladderLines; // 使用 QList


    Synthetic(const QString& id,
              const QDateTime& startTime,
              const QDateTime& endTime,
              const QList<DurationCarrier>& durations,
              const QList<LadderLineCarrier>& ladderLines)
        : id(id),
          startTime(startTime),
          endTime(endTime),
          durations(durations),
          ladderLines(ladderLines)
    {}

    Synthetic(const QDateTime &startTime = QDateTime(QDate::currentDate()),
              const QDateTime &endTime = QDateTime(QDate::currentDate()))
        : Synthetic(QUuid::createUuid().toString(), startTime, endTime, QList<DurationCarrier>(), QList<LadderLineCarrier>())
    {}

    Synthetic(const QDateTime& startTime, const QDateTime& endTime, const QList<DurationCarrier>& durations, const QList<LadderLineCarrier>& ladderLines)
        : Synthetic(QUuid::createUuid().toString(), startTime, endTime, durations, ladderLines)
    {}


    Synthetic(const QDateTime& startTime, const QDateTime& endTime, const QList<DurationCarrier>& durations)
        : Synthetic(QUuid::createUuid().toString(), startTime, endTime, durations, QList<LadderLineCarrier>())
    {}


    Synthetic(const QDateTime& startTime, const QDateTime& endTime, const QList<LadderLineCarrier>& ladderLines)
        : Synthetic(QUuid::createUuid().toString(), startTime, endTime, QList<DurationCarrier>(), ladderLines)
    {}


    // 将结构体转换为 JSON 对象的函数
    QJsonObject toJson() const {
        QJsonObject obj;
        obj["id"] = id;
        // 使用 ISO 日期格式输出 QDateTime，这样便于后续的解析
        obj["startTime"] = startTime.toString(Qt::ISODate);
        obj["endTime"] = endTime.toString(Qt::ISODate);

        QJsonArray durationsArray;
        for (const auto &duration : durations) {
            // 假设 duration 有 toJson() 方法，否则需要自己实现
            durationsArray.append(duration.toJson());
        }

        obj["durations"] = durationsArray;
        return obj;
    }
};

Q_DECLARE_METATYPE(Synthetic)

#endif // SYNTHETIC_HPP
